home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / audio / rock / rock.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.5 KB  |  256 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    rock - 
  19.  *        play some samples
  20.  *
  21.  *         Paul Haeberli and Bruce Karsh - 1991 
  22.  */ 
  23. #include "math.h"
  24. #include "stdio.h"
  25. #include "gl.h"
  26. #include "device.h"
  27. #include "sample.h"
  28.  
  29. sample *p1, *p2, *p3, *p4;
  30. sample *go, *stop, *yeah, *rest;
  31. sample *in, *di, *hollywood;
  32.  
  33. main(argc,argv)
  34. int argc;
  35. char **argv;
  36. {
  37.     sample *s1, *s2, *s3, *s4, *s;
  38.     int max;
  39.     int j;
  40.  
  41.     sethumanize(0.02,0.2);
  42.     if(argc>1)
  43.     setbpm(atof(argv[1]));
  44.     else
  45.     setbpm(405.0);
  46.     p1 = readsample("bash1.a");
  47.     p2 = readsample("bash2.a");
  48.     p3 = readsample("bash3.a");
  49.     p4 = readsample("bash4.a");
  50.     hollywood = readsample("hollywood.a");
  51.     expandsample(hollywood);
  52.     rest = clonesample(p4);
  53.     scalesample(rest,0.0);
  54.     go = readsample("go.a");
  55.     stop = readsample("stop.a");
  56.     yeah = readsample("yeah.a");
  57.     in = readsample("in.a");
  58.     di = readsample("di.a");
  59.     donote(in);
  60.     donote(in);
  61.     donote(in);
  62.     donote(di);
  63.     donote(di);
  64.     donote(di);
  65.         donote(go);
  66.         donote(go);
  67.         donote(go);
  68.     donote(in);
  69.     donote(di);
  70.         donote(go);
  71.     while(1) {
  72.     j++;
  73.     if((j%5) == 0) {
  74.         donote(go);
  75.         donote(go);
  76.         donote(in);
  77.         donote(go);
  78.         donote(in);
  79.         donote(go);
  80.         donote(in);
  81.         donote(di);
  82.         donote(go);
  83.         donote(in);
  84.         donote(di);
  85.         donote(go);
  86.         donote(in);
  87.         donote(di);
  88.         donote(go);
  89.         donote(in);
  90.         donote(di);
  91.         donote(go);
  92.         donote(go);
  93.         donote(go);
  94.         donote(go);
  95.         donote(go);
  96.         donote(go);
  97.         donote(go);
  98.         donote(go);
  99.         donote(go);
  100.         donote(go);
  101.         donote(go);
  102.         donote(go);
  103.         donote(go);
  104.         donote(go);
  105.         donote(go);
  106.         donote(in);
  107.         donote(di);
  108.         donote(go);
  109.         donote(in);
  110.         donote(di);
  111.         donote(go);
  112.         donote(in);
  113.         donote(di);
  114.         donote(go);
  115.         donote(in);
  116.         donote(di);
  117.         donote(go);
  118.         donote(in);
  119.         donote(di);
  120.         donote(go);
  121.         donote(hollywood);
  122.         donote(rest);
  123.         donote(rest);
  124.  
  125.         donote(rest);
  126.         donote(rest);
  127.         donote(rest);
  128.         } else if( (j%10) == 0 ) {
  129.         donote(stop);
  130.         donote(rest);
  131.         donote(rest);
  132.         donote(rest);
  133.         donote(rest);
  134.         donote(rest);
  135.         donote(rest);
  136.         donote(rest);
  137.         donote(yeah);
  138.         donote(yeah);
  139.         donote(yeah);
  140.         donote(yeah);
  141.         donote(yeah);
  142.         donote(yeah);
  143.         donote(yeah);
  144.         donote(yeah);
  145.         donote(yeah);
  146.         donote(yeah);
  147.         donote(yeah);
  148.         donote(yeah);
  149.         donote(rest);
  150.         donote(rest);
  151.         } else if( (j%10) == 0 ) {
  152.         donote(stop);
  153.         donote(rest);
  154.         donote(rest);
  155.         donote(rest);
  156.         donote(rest);
  157.         donote(rest);
  158.         donote(rest);
  159.         donote(rest);
  160.         donote(yeah);
  161.         donote(yeah);
  162.         donote(yeah);
  163.         donote(yeah);
  164.         donote(yeah);
  165.         donote(yeah);
  166.         donote(yeah);
  167.         donote(yeah);
  168.         donote(yeah);
  169.         donote(yeah);
  170.         donote(yeah);
  171.         donote(yeah);
  172.         donote(yeah);
  173.         donote(yeah);
  174.         donote(yeah);
  175.         donote(yeah);
  176.         donote(yeah);
  177.         donote(yeah);
  178.         donote(yeah);
  179.         donote(yeah);
  180.     } else {
  181.         donote(p1);
  182.         donote(rest);
  183.     }
  184.     donote(p4);
  185.         donote(rest);
  186.     donote(p1);
  187.         donote(rest);
  188.     donote(p4);
  189.         donote(rest);
  190.     donote(p1);
  191.         donote(go);
  192.     donote(p4);
  193.         if(j & 2)
  194.         donote(go);
  195.         else
  196.         donote(p2);
  197.  
  198.     donote(p1);
  199.  
  200.     if(j & 1)
  201.         donote(go);
  202.      else
  203.         donote(p2);
  204.  
  205.     donote(p4);
  206.     donote(p1);
  207.     donote(p1);
  208.     donote(p4);
  209.     donote(p4);
  210.     if(j&1)
  211.         donote(yeah);
  212.     else
  213.         donote(stop);
  214.     } 
  215.  
  216. maybe()
  217. {
  218.     if((random()%8) == 0)
  219.     donote(rest);
  220.     else
  221.     donote(p2);
  222. }
  223.  
  224. randbeat()
  225. {
  226.     switch(random()%10) {
  227.     case 0:
  228.     case 1:
  229.     case 2:
  230.     case 3:
  231.         donote(go);
  232.         break;
  233.     case 4:
  234.     case 5:
  235.     case 6:
  236.     case 7:
  237.         donote(stop);
  238.         break;
  239.     case 8:
  240.     case 9:
  241.         donote(rest);
  242.         break;
  243.     }
  244. }
  245.  
  246. double now;
  247.  
  248. donote(s)
  249. sample *s;
  250. {
  251.     flushnotes(now-4.0);
  252.     playnote(s,now,1.0);
  253.     now = now+1;
  254. }
  255.